var app = getApp(),
  $ = require("../../utils/httpHelper.js")
Page({
  data: {
    // tab切换  
    currentTab: 0,
    re_pay:false,
    objarr: [],
    page: 1,
    pagesize: 6,
    totalpage: 0,//最大页数
    height: 0,
    user_status:'n',
    cats:[],
    nomore: true,
  },
  onLoad: function () {
    var self = this;
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        self.setData({ height: res.windowHeight - 90 })
      }
    })
    this.onShow()
    
    
  },
  onShow(){
    console.log(app.globalData.shangc_id)
    if (!app.check_empty(app.globalData.shangc_id)) {
      this.setData({
        currentTab: app.globalData.shangc_id,
      })
      app.globalData.shangc_id = ''
    }
    this.getData()
  },
  getData(){
    this.setData({
      page: 1,
    })
    let par = {
      types: this.data.currentTab,
      page:this.data.page,
      page_size:this.data.pagesize
    }
    $.httpPost("good_list", par, (data, err) => {
      this.setData({
        objarr:data.data.list,
        totalpage:data.data.total_page
      })
    })
  },
  clicktab(e){
    console.log(e.target)
    let tab = e.target.dataset.tab
    if (this.data.currentTab != tab){
      this.setData({
        currentTab: tab,
        page:1
      })
    }
    this.getData()
  },
  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params = {
        types: this.data.currentTab,
        page: this.data.page,
        page_size: this.data.pagesize
      }
      $.httpPost("good_list", params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })


    }

  },

  todetail(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/goods/goods_detail_buy?id=' + id + '&status=' + 'good',
    })
  },
    
})  